package com.xmb.wechat.delegate;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xmb.wechat.R;
import com.xmb.wechat.baserecyclerview.BaseRecyclerViewManager;
import com.xmb.wechat.bean.PYQCommentsBean;

import java.util.ArrayList;

/**
 * @Author lijiangop
 * @CreateTime 2020/5/14 10:44
 */
class PYQCommentsDelegate extends BaseRecyclerViewManager {

    public PYQCommentsDelegate(Context context, RecyclerView recyclerView) {
        super(context, recyclerView);
    }

    @Override
    public BaseQuickAdapter initAdapter() {
        return new BaseQuickAdapter<PYQCommentsBean, BaseViewHolder>(R.layout.item_pyq_comments, new ArrayList<>()) {
            @Override
            protected void convert(BaseViewHolder helper, PYQCommentsBean item) {
                TextView textView = helper.getView(R.id.tv);
                SpannableString spannableString;
                if (item.getType() == 0) {
                    spannableString = new SpannableString(item.getCommenter() + ": " + item.getCommentValue());
                    spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#596B8F")),
                            0, item.getCommenter().length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
                    spannableString.setSpan(new StyleSpan(Typeface.BOLD),
                            0, item.getCommenter().length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
                    textView.setText(spannableString);
                } else {
                    spannableString = new SpannableString(item.getCommenter() + "回复" + item.getCommenteder() + ": " + item.getCommentValue());
                    spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#596B8F")),
                            0, item.getCommenter().length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
                    spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#596B8F")),
                            item.getCommenter().length() + 2, item.getCommenter().length() + 2 + item.getCommenteder().length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
                    spannableString.setSpan(new StyleSpan(Typeface.BOLD),
                            0, item.getCommenter().length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
                    spannableString.setSpan(new StyleSpan(Typeface.BOLD),
                            item.getCommenter().length() + 2, item.getCommenter().length() + 2 + item.getCommenteder().length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
                    textView.setText(spannableString);
                }
            }
        };
    }
}
